

import matplotlib.pyplot as plt
import numpy as np

#%% Texas
name = "Texas"
av01 = [0.37665580960450623, 0.2571108437121825, 0.12108966534258019, 0.17300199292789648, 0.13543331628507452, 0.07112275725083811, 0.030862138412514086, 0.07549747174901802, 0.12463064728376354, 0.170368099526493, 0.2107275655290994]
av02 = [0.46160016306940826, 0.3666950426834259, 0.13730643137777815, 0.1862464358174858, 0.12711248368962486, 0.060260465483614335, 0.04560421832198795, 0.07742147196768043, 0.11037447688638727, 0.1359751742556954, 0.15719118036970745]
av03 = [0.38725951745193815, 0.3622975719728165, 0.092057025804431, 0.16298739260022557, 0.13537677939370685, 0.08573223942377137, 0.04420925768355573, 0.05226142593786965, 0.10030024855620345, 0.15389558720674323, 0.20343445955421757]
av04 = [0.43267308636130203, 0.22973446943621487, 0.12999412378539218, 0.2125543177920726, 0.1645603254782024, 0.08713271428888651, 0.040583005913769295, 0.07735329626383448, 0.14592650803055435, 0.19981890207760108, 0.2439230983395223]
av05 = [0.4502560691923994, 0.3480972197956003, 0.11602390418351784, 0.21439481008569178, 0.18200736054587888, 0.1136108974575679, 0.04247675424847517, 0.045310064347123445, 0.10308664666475297, 0.16330193801480636, 0.21678438000386369]
origin = [0.4034216929591746, 0.31890339884318114, 0.11416556328038796, 0.17052324812834152, 0.1326970967598368, 0.07223477399198391, 0.03267347236216863, 0.06600127679550273, 0.11225197139031592, 0.15162467010256925, 0.18345965130739209]
avm01 = [0.37693846474704185, 0.2525881316733189, 0.1400579252440619, 0.17713293417617565, 0.13947874878256095, 0.07257888596620606, 0.031752972142049134, 0.05977525809480739, 0.10619556450319036, 0.14829034631470225, 0.18455789087777094]
#avm02 = [0.3827358099925211, 0.31340930779365855, 0.1182094303413031, 0.17844771050857766, 0.1494097034021582, 0.0897351883021017, 0.044040401245686416, 0.052394395670455014, 0.10157020376172059, 0.1477189137694197, 0.1908632464874703]
avm02 = [0.3801518210383237, 0.2692192105299064, 0.1073504685509608, 0.13215249611222749, 0.11325879526086106, 0.07581729128262228, 0.04858688606595714, 0.06365388431102206, 0.10023684617557459, 0.13298936598735328, 0.1628168643660512]
avm03 = [0.39955665133485446, 0.4076072495196184, 0.11024897236688375, 0.06370851913782404, 0.05631012609840034, 0.04846212671901393, 0.038184967849842016, 0.04193556047127304, 0.05022662745572717, 0.05843858381990569, 0.06557040751122631]
#avm04 = [0.3426446257558146, 0.3686730278872232, 0.07944883948667589, 0.13922115752335237, 0.1347950223567117, 0.10076827869241363, 0.07187909286649971, 0.058907673732995984, 0.07267238048100255, 0.10058584020098302, 0.13143311311822206]
#avm04=[0.308095662518448, 0.16264604871258675, 0.1557250974390941, 0.1497066837358598, 0.06752189032667046, 0.0014959708534001085, 0.045971545464347834, 0.06957389413098254, 0.0794520938985316, 0.07922776457658624, 0.08140273153397272]
avm04 = [0.4110393143918371, 0.18821090234563248, 0.09534779698643898, 0.11162911856123822, 0.07490806436570877, 0.04706153946504996, 0.05116470073618871, 0.07060643092796154, 0.08587172420918751, 0.09810742694043412, 0.11248594973012416]
avm05 = [0.4243544104965417, 0.163268859334574, 0.10780864813661721, 0.10409049444487446, 0.08596686370468688, 0.0607415816576975, 0.04637246295293646, 0.04186490762806161, 0.049351414816268944, 0.060317231023946385, 0.07194846607798878]
data = np.array([avm05,avm04,avm03,avm02,avm01,origin, av01,av02,av03,av04,av05])
#%% Actor
name = "Actor"
Gamma0 = [4.20322901,2.13439428,4.97136259,1.74358925,3.25165542,2.68236303,1.795872,1.25811388,1.11813501,1.48951374,2.49131421]
Gamma1 = [4.11792256, 2.36151826, 5.78154838, 1.27418058, 3.32610651, 3.85831819, 3.30269399, 2.06300387, 0.75705602, 2.66353515, 5.40842431]
Gamma2 = [4.33344913, 3.42478837, 8.04929917, 1.26134185, 4.83257181, 5.31293739, 4.02477282, 2.13316998, 0.95765195, 2.96362086, 5.10591847]
Gamma3 = [4.16473415, 2.1515957, 4.79044217, 1.85393925, 3.83070399, 3.48881684, 2.34892377, 1.3270756, 1.09083934, 2.33106232, 3.43765007]
Gamma4 = [4.13780368, 2.10175444, 5.71221831, 1.46472236, 4.12246404, 4.48322339, 3.55256773, 1.90883252, 0.95793803, 3.17386904, 5.72864373]
Gamma5 = [4.13871491, 2.16188517, 5.27228796, 1.21339295, 3.84717194, 4.4881916, 3.81959301, 2.27727104, 0.93351739, 3.16936406, 5.73247436]
Gamma_1 = [4.10963277, 1.93702129, 4.01986201, 1.80162798, 2.78257242, 2.0147036, 1.46103526, 1.28480475, 1.1420237, 1.27073292, 2.10471192]
Gamma_2 = [4.35806618, 2.3109815, 5.00502269, 1.35355161, 3.01238299, 2.93340342, 2.21077786, 1.39103209, 0.843537, 1.66768738, 2.91601797]
Gamma_3 = [4.226904, 2.85196415, 4.6147469, 1.16325099, 2.23692544, 2.49472324, 2.16087829, 1.53901763, 0.75997924, 1.5192355, 3.04171405]
Gamma_4 = [4.23384456, 1.98671137, 3.60926263, 1.31671948, 1.61856975, 1.84734512, 1.64165688, 1.22958336, 0.75486963, 1.12246136, 2.15424393]
Gamma_5 = [4.27836023, 1.21702333, 2.40032715, 1.61306436, 0.97493325, 1.50772305, 1.60620995, 1.19737637, 0.79994247, 1.3025872, 2.42382233]
data = np.array([Gamma_5, Gamma_4, Gamma_3, Gamma_2, Gamma_1, Gamma0, Gamma1, Gamma2, Gamma3, Gamma4, Gamma5])
#%%


tag = ['-0.5','-0.4','-0.3','-0.2','-0.1','0.0', '+0.1','+0.2','+0.3','+0.4','+0.5']
data=np.delete(data,0,axis=1)

bar_width = 0.6
index = np.arange(len(tag))

t=1 #删去k=0时t=1,否则t=0
#plt.bar(index, height=data[:,10], bottom=np.sum(data[:,:10],axis=1), width=bar_width, color='c', label='k={}'.format(10+t))
plt.bar(index, height=data[:,9], bottom=np.sum(data[:,:9],axis=1), width=bar_width, color='#bc1f24',edgecolor='w', label='k={}'.format(9+t),zorder=10)
plt.bar(index, height=data[:,8], bottom=np.sum(data[:,:8],axis=1), width=bar_width, color='#f04b3c',edgecolor='w', label='k={}'.format(8+t),zorder=10)
plt.bar(index, height=data[:,7], bottom=np.sum(data[:,:7],axis=1), width=bar_width, color='#fe9a99',edgecolor='w', label='k={}'.format(7+t),zorder=10)
plt.bar(index, height=data[:,6], bottom=np.sum(data[:,:6],axis=1), width=bar_width, color='#fdc07c',edgecolor='w', label='k={}'.format(6+t),zorder=10)
plt.bar(index, height=data[:,5], bottom=np.sum(data[:,:5],axis=1), width=bar_width, color='#c7afd6',edgecolor='w', label='k={}'.format(5+t),zorder=10)
plt.bar(index, height=data[:,4], bottom=np.sum(data[:,:4],axis=1), width=bar_width, color='#b1c3e7',edgecolor='w', label='k={}'.format(4+t),zorder=10)
plt.bar(index, height=data[:,3], bottom=np.sum(data[:,:3],axis=1), width=bar_width, color='#a0d9e4',edgecolor='w', label='k={}'.format(3+t),zorder=10)
plt.bar(index, height=data[:,2], bottom=np.sum(data[:,:2],axis=1), width=bar_width, color='#26bccf',edgecolor='w', label='k={}'.format(2+t),zorder=10)
plt.bar(index, height=data[:,1], bottom=np.sum(data[:,:1],axis=1), width=bar_width, color='#94d695',edgecolor='w', label='k={}'.format(1+t),zorder=10)
plt.bar(index, height=data[:,0], bottom=0,                         width=bar_width, color='#43b263',edgecolor='w', label='k={}'.format(0+t),zorder=10)

# zorder=10设置图层位置
#plt.axhline(y=0.2, ls="-", c="gray", linewidth=0.3)#添加水平直线
plt.grid(axis='y', c="#d9d9d9",zorder=2)

fontsize=13
plt.legend(loc=2,borderpad=0.1,bbox_to_anchor=(1.01,1), fontsize=fontsize-1)  # 显示图例
plt.xticks(index + bar_width/3, tag, rotation=55)
plt.tick_params(labelsize=fontsize, zorder=20)
# plt.ylim(0,0.6)
plt.ylabel(r'${}|\gamma_{2,k}|}$', size=fontsize+3)  # 纵坐标轴标题
plt.xlabel(r'${n_2^\prime/n_2-1}$', size=fontsize+3)
plt.title(name, size=fontsize+3)
# ax=plt.gca()
# ax.spines['bottom'].set_linewidth(2);###设置底部坐标轴的粗细
# ax.spines['left'].set_linewidth(2);####设置左边坐标轴的粗细
# ax.spines['right'].set_linewidth(2);###设置右边坐标轴的粗细
# ax.spines['top'].set_linewidth(2);####设置上部坐标轴的粗细
plt.gcf().subplots_adjust(left=0.13, right=0.8, bottom=0.22, top=0.945)
#plt.figure(figsize=(300,50))

plt.savefig('{}_stackbar.svg'.format(name), format='svg', dpi=150, bbox_inches='tight')
plt.show()
